/*主页JS逻辑*/
$(function(){
	setIOSAddr();
});
//第一部分
var first=avalon.define({
	$id:"first-wrap"
});
//第一部分
var first=avalon.define({
	$id:"first-wrap"
});

//教师端部分
var teaModel = avalon.define({
	$id : 'teaModel',
	showBarcode : function(){
		if(is_weixin()){
			$('#weixinCover').css('display','block');
			return;
		}
		if(__isAndroid()){
			location.href = 'http://udodl.howdo.cc/scm/oapi/platform/latest/download/project/19/plat/1';
			return;
		}else if(__isIOS()){
			location.href=$("#tea_url").text();
			return;
		}
		$('#teaBarcode').empty().qrcode(location);
		$('#teaBarcodeModel').modal({
			width : 280
		});
	}
});

//学生端部分
var stuModel = avalon.define({
	$id : 'stuModel',
	showBarcode : function(){
		if(is_weixin()){
			$('#weixinCover').css('display','block');
			return;
		}
		if(__isAndroid()){
			location.href = 'http://udodl.howdo.cc/scm/oapi/platform/latest/download/project/18/plat/1';
			return;
		}else if(__isIOS()){
			location.href=$("#stu_url").text();		
			return;
		}
		$('#stuBarcode').empty().qrcode(location);
		$('#stuBarcodeModel').modal({
			width : 280
		});
	}
});

//关于部分
var tabHeight = 210;
var aboutModel=avalon.define({
	$id:"about-wrap",
	currentTab : 0,
	tabTop : 0,
	timeUp : function(){
		var len = $('#timeList .tab').length;
		if(aboutModel.currentTab >= len-1)	return;
		$('.currentTabItem').removeClass('currentTabItem');
		var currentTab = ++aboutModel.currentTab;
		$('#timeList .tabItem:eq('+currentTab+')').addClass('currentTabItem');
		$("#timeList").stop().animate({scrollTop:tabHeight*currentTab},'500','swing');
	},
	timeDown : function(){
		if(aboutModel.currentTab <= 0)	return;
		$('.currentTabItem').removeClass('currentTabItem');
		var currentTab = --aboutModel.currentTab;
		$('#timeList .tabItem:eq('+currentTab+')').addClass('currentTabItem');
		$("#timeList").stop().animate({scrollTop:tabHeight*currentTab},'500','swing');
	}
});
//页脚copyRight的年份动态显示
var right=avalon.define({
	$id:"copyRight",
	year:new Date().getFullYear()
});

/*绑定ios教师端和学生端地址*/
function setIOSAddr(){
	$.ajax({
			type:"get",
			url:"http://udodl.howdo.cc/scm/oapi/platform/latest?project=18&plat=2",  //学生端ios地址
			dataType:'json',
			async:false,
			success:function(data){
				var resultUrl=data.data.url || data.data.plist;
				$("#stu_url").text('itms-services://?action=download-manifest&amp;url='+resultUrl);

			},
			error:function(data){
				alert("获取安装包异常，请刷新重试");	
			}
		
		});
	$.ajax({
			type:"get",
			url:"http://udodl.howdo.cc/scm/oapi/platform/latest?project=19&plat=2",  //教师端ios地址
			dataType:'json',
			async:false,
			success:function(data){
				var resultUrl=data.data.url || data.data.plist;
				$("#tea_url").text('itms-services://?action=download-manifest&amp;url='+resultUrl);
			},
			error:function(data){
				alert("获取安装包异常，请刷新重试");	
			}
		
		});
}

/**
 * 是否是android机器
 * @returns {boolean}
 * @private
 */
function __isAndroid(){
	var u = navigator.userAgent, app = navigator.appVersion;
	return u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
}

/**
 * 是否是ios机器
 * @returns {boolean}
 * @private
 */
function __isIOS(){
	var u = navigator.userAgent, app = navigator.appVersion;
	return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
}

/**
 * 是否是pc浏览器
 * @returns {boolean}
 * @private
 */
function __isPC(){
	var userAgentInfo = navigator.userAgent;
	var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
	var flag = true;
	for (var v = 0; v < Agents.length; v++) {
		if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
	}
	return flag;
}

/* 
 *是否是微信浏览器 */
function is_weixin(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.match(/MicroMessenger/i)=="micromessenger") {
		return true;
 	} else {
		return false;
	}
}
